import 'package:flutter/material.dart';

class DDReadField extends StatelessWidget {
  final int fieldCount;
  // 第一列
  final String labelText;
  final String valueText;
  final double labelWidth;
  final Color valueColor;
  // 第二列
  final String label2Text;
  final String value2Text;
  final double label2Width;
  final Color value2Color;

  DDReadField({
    this.fieldCount = 1,
    this.labelText = "",
    this.valueText = "",
    this.labelWidth = 80.0,
    this.valueColor = Colors.black,
    this.label2Text = "",
    this.value2Text = "",
    this.label2Width = 80.0,
    this.value2Color = Colors.black,
  });

  @override
  Widget build(BuildContext context) {
    if (fieldCount == null || fieldCount == 1) {
      return buildField(context, labelText, valueText, labelWidth, valueColor);
    } else {
      return Row(
        children: <Widget>[
          Column(
            children: <Widget>[
              buildField(context, labelText, valueText, labelWidth, valueColor),
            ],
          ),
          Column(
            children: <Widget>[
              buildField(
                  context, label2Text, value2Text, label2Width, value2Color),
            ],
          ),
        ],
      );
    }
  }

  ///
  /// 构建字段行
  ///
  Widget buildField(BuildContext context, String label, String value,
      double width, Color color) {
    List<Widget> widgetList = [];
    widgetList.add(
      new SizedBox(
        width: width,
        child: Padding(
          padding: EdgeInsets.fromLTRB(5.0, 8.0, 5.0, 8.0),
          child: Text(label),
        ),
      ),
    );
    widgetList.add(
      new Padding(
        padding: EdgeInsets.fromLTRB(5.0, 8.0, 5.0, 8.0),
        child: Text(
          value,
          style: TextStyle(color: color),
          softWrap: true,
        ),
      ),
    );

    return Row(children: widgetList);
  }
}
